import { Row, Col, Carousel, Icon } from 'antd';
import {WeaLocaleProvider, WeaTable} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import Slider from 'react-slick';
import { isEqual, isEmpty } from 'lodash';
import { formatData, loadRemind, openLinkUrl } from '../../util/common';
import objectAssign from 'object-assign';
//文档中心元素
class NewsType extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            count: 0
        }
    }
    shouldComponentUpdate(nextProps, nextState){
        return !isEqual(this.props, nextProps) || !isEqual(this.state, nextState)
    }
    componentDidMount(){
        const { eid } = this.props;
        const pictureWidth = $(`.homepage #news_${eid} div`).width()
        const elementWidth = $(`.homepage #content_view_id_${eid}`).width();
        let count =0;
        if(pictureWidth !==null && elementWidth!==null){
            count = parseInt(elementWidth/(pictureWidth + 10));
            if(count!=0 && count != this.state.count){
                this.setState({
                    count
                });
            }
        }
    }
    componentDidUpdate(){
        const { eid } = this.props;
        const pictureWidth = $(`.homepage #news_${eid} div`).width()
        const elementWidth = $(`.homepage #content_view_id_${eid}`).width();
        let count =0;
        if(pictureWidth !==null && elementWidth!==null){
            count = parseInt(elementWidth/(pictureWidth + 20));
            if(count!=0 && count != this.state.count){
                this.setState({
                    count
                });
            }
        }
    }
    render() {
        const { eid, data={}, esetting={}, canEdit, contentview={} } = this.props;
        const { linkmode, fontStyle = {} } = esetting;
        const { contentfontsize = '12' } = fontStyle;
        const { tabsetting={}, srcStyle={} } = data;
        const { style: dataStyle={}, rollDirection, scrollSpeed='2000' } = tabsetting;
        const {autoheight = '0', pictureheight = '108px', picturewidth = '120px'} = srcStyle;
        const { abstractColor = '#797979', abstractFont = '微软雅黑', abstractSize = '12', abstractstyle, abstractWeight = '0',
            titleColor = '#000000', titleFont = '微软雅黑', titleSize = '16', titlestyle,
            titleWeight= '0' } = dataStyle;
        const list = data.data;
        if (list && list.length === 0){
            return (
                <div className = "ant-table-placeholder">
                    <span> <i className = "anticon anticon-frown"></i>{getLabel(83553, '暂无数据')}</span>
                </div>
            );
        }
        //tab设置信息
        const { height, width, showModeId, imgs, imgsWithDocSubject=[] } = tabsetting;
        let columns = new Array;
        let imgStyle = {
            width: picturewidth,
            height: pictureheight
        };
        let style = {
            verticalAlign: 'top',
            width: picturewidth,
            height: pictureheight
        };
        if(autoheight == '1'){
            imgStyle = {
                verticalAlign: 'top',
                width: picturewidth,
                height: 'auto'
            };
            style = {
                verticalAlign: 'top',
                width: picturewidth,
                height: 'auto'
            };
        }
        let listStyle2 = {
            width: '100%',
            height: '100%'
        };
        if(autoheight == '0' && imgStyle.height && imgStyle.height.indexOf('px')!=-1 && imgStyle.width.indexOf('px')!=-1){
            listStyle2 = {
                width: imgStyle.width,
                height: imgStyle.height
            };
        }

        let docHtml = '';
        switch (parseInt(showModeId)) {
            case 2: //上图式
                imgStyle['margin'] = '0 auto';
                let lHtml = list.map((item, i) => {
                    let imghtml = null;
                    if (!isEmpty(imgs)) {
                        let img = imgs[i] || '/images/homepage/noimgdefault_wev8.jpg';
                        if (typeof img == 'object' && img.length > 1) {
                            imghtml = <div id={`news_silde_${eid}`} className="news-silde">
                                <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@i5ubc4@${i}`} autoplay >
                                    {img.map(o => {
                                        return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@uyjkw9@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link} eid={eid} src={o} style={listStyle2}/></div>
                                    })}
                                </Carousel>
                            </div>
                        } else {
                            imghtml = <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@wp4hhx@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link}  eid={eid} src={img}/>
                        }
                    }
                    let list_new = [];
                    for (var i in item){
                        if(i != 'summary' && i != 'docsubject' && i != 'doccreater'){
                            list_new.push(item[i])
                        }
                    }
                    return <div id={`news_${eid}`} className={"portal-news-com"}>
                        <div style={imgStyle}>{imghtml}</div>
                        <div style={{width: imgStyle.width, margin: '0 auto', paddingTop: '10px'}}>
                            {
                                item.docsubject ? <div style={{marginRight: '10px' , marginBottom: '10px'}}>{loadRemind(item.docsubject, esetting.linkmode, esetting.isremind, undefined,undefined,'7', eid, style={ fontFamily: 'PingFangSC-Regular',
                                        fontSize: '14px !important', color: '#333333', letterSpacing: '-0.09px'})}</div>
                                    : <div style={{ marginTop: '10px', marginRight: '10px' , marginBottom: '10px'}}></div>
                            }
                            {item.summary && <div title={item.summary} style={{marginBottom:'10px'}}><div className={'portal-news-summary'} style={{display: '-webkit-box', overflow: 'hidden', textOverflow: 'ellipsis', WebkitLineClamp: '2', WebkitBoxOrient: 'vertical'}}>{item.summary}</div></div>}
                            <div style={{display: 'inline-block', position: 'relative', width: '100%'}}>
                                {item.doccreater ? <div style={{display: 'inline-block' , marginRight: '10px' ,marginBottom: '10px', width: '60px'}}>{loadRemind(item.doccreater, esetting.linkmode, esetting.isremind, undefined,undefined,'7', eid,style={lineHeight:'1'})}</div> : <div style={{display: 'inline-block' ,marginTop: '10px' , marginRight: '10px' ,marginBottom: '10px'}}></div>}
                                <div style={{display: 'inline-block', bottom: '15px', float: 'right', width: 'calc(100% - 60px - 10px)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis'}}>
                                    {
                                        list_new.map((item_new) => {
                                            return  <div style={{display: 'inline-block', fontSize: '12px', color: '#999999', letterSpacing: '-0.08px'}}>{item_new}</div>
                                        })
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                });
                docHtml = <div className={"portal-news-content"}>{lHtml}</div>
                break;
            case 3: //左图式
                let html = list.map((item, i) => {
                    let imghtml = null;
                    if (!isEmpty(imgs)) {
                        let img = imgs[i] || '/images/homepage/noimgdefault_wev8.jpg';
                        if (typeof img == 'object' && img.length > 1) {
                            img = img.filter(item => {
                                if(item != '/images/homepage/noimgdefault_wev8.jpg'){ return item; }
                            })
                            imghtml = <div id={`news_silde_${eid}`} className="news-silde">
                                <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@mqzb0q@${i}`} autoplay >
                                    {img.map(o => {
                                        return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@6g7geh@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link} eid={eid} src={o} style={listStyle2}/></div>
                                    })}
                                </Carousel>
                            </div>
                        } else {
                            imghtml = <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@4ig180@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link}  eid={eid} src={img}/>
                        }
                    }
                    let style_fs = objectAssign({}, imgStyle, {float:'left', marginBottom: '15px'});
                    let list_new = [];
                    for (var i in item){
                        if(i != 'summary' && i != 'docsubject' && i != 'doccreater'){
                            list_new.push(item[i])
                        }
                    }

                    return <div style={{overflow: 'auto', overflowY: 'hidden', width:'100%',marginBottom:'10px'}} className={"portal-news-com"}>
                        <div style={style_fs}> {imghtml}</div>
                        <div style={{overflow: 'hidden', paddingLeft: '3px'}}>
                            {
                                item.docsubject ? <div style={{ marginTop: '10px', marginRight: '10px' }}>{loadRemind(item.docsubject, esetting.linkmode, esetting.isremind, undefined,undefined,'7', eid,style={ fontFamily: 'PingFangSC-Regular',
                                        fontSize: '14px !important', color: '#333333', letterSpacing: '-0.09px'})}</div>
                                    :<div style={{ marginTop: '10px', marginRight: '10px' , marginBottom: '10px'}}></div>
                            }
                            {
                                item.summary && <div><div className={'portal-news-summary'} style={{width: '99%', overflow: 'hidden', textOverflow: 'ellipsis', WebkitLineClamp: '2',
                                    WebkitBoxOrient: 'vertical', display: '-webkit-box',  marginBottom: '10px'}} title={item.summary}>{item.summary}</div></div>
                            }
                            <div style={{display: 'inline-block', position: 'relative', width: '100%'}}>
                                {item.doccreater ? <div style={{display: 'inline-block' , marginRight: '10px' ,marginBottom: '10px'}}>{loadRemind(item.doccreater, esetting.linkmode, esetting.isremind,undefined,undefined,undefined,undefined,style={lineHeight:'1'})}</div> : <div style={{display: 'inline-block' ,marginTop: '10px' , marginRight: '10px' ,marginBottom: '10px'}}></div>}
                                <div style={{display: 'inline-block', position: 'absolute', float: 'right', width: '100%'}}>
                                    {
                                        list_new.map((item_new) => {
                                            if(typeof(item_new) == "object"){
                                                return  <div style={{display: 'inline-block', paddingLeft: '5px', fontSize: '12px', color: '#999999', letterSpacing: '-0.08px'}}>{item_new.name}</div>
                                            }
                                            return  <div style={{display: 'inline-block', paddingLeft: '5px', fontSize: '12px', color: '#999999', letterSpacing: '-0.08px'}}>{item_new}</div>
                                        })
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                });
                docHtml = <div className={"portal-news-content"}>{html}</div>
                break;
            case 4: //列表式2
                let html4 = null;
                let imghtml = null;
                let imghtml2=[];
                let j=0;
                const imgs_new = imgs.filter(item => {
                    if(item != '/images/homepage/noimgdefault_wev8.jpg'){ return item; }
                })

                if (!isEmpty(imgs)) {
                    if (imgs_new.length > 1) {
                        imgs.map((item,i) => {
                            imghtml2[j]=imgs[i];
                            j++;
                        });
                        if(imghtml2.length==0){
                            imghtml2[0]='/images/homepage/noimgdefault_wev8.jpg';
                        }
                        let ihtml = imghtml2.map((item, i) => {
                            let img = imghtml2[i];
                            if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                            if(img == '/images/homepage/noimgdefault_wev8.jpg'){
                                return
                            }
                            // if (img.indexOf("|") !== -1) img = img.split("|")[0];
                            return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@cxpi25@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link} style={listStyle2} eid={eid} src={img}/></div>
                        });
                        imghtml = <div style={{height: style.height || '100%'}} id={`news_silde_${eid}`} className="news-silde">
                            <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@ll2047`} autoplay>
                                {ihtml}
                            </Carousel>
                        </div>
                    }else{
                        let img = imgs_new[0];
                        let x = 0;
                        imgs.map((item, index) => {
                            if(item != '/images/homepage/noimgdefault_wev8.jpg'){
                                x = index;
                            }
                        })
                        if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                        if (img.indexOf("|") !== -1) img = img.split("|")[0];
                        imghtml = <div id={`news_silde_${eid}`} className='news-silde'>
                            <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@ui2llh`} linkmode={linkmode} link={imgsWithDocSubject[x] && imgsWithDocSubject[x].docsubject && imgsWithDocSubject[x].docsubject.link} style={listStyle2} eid={eid} src={img}/></div>
                        </div>
                    }
                }
                columns = formatData(list[0], esetting);
                style['paddingTop'] = '6px';
                html4 = <table style={{width: '100%',tableLayout: 'fixed'}}><tr>
                    <td style={style}>
                        {imghtml}
                    </td>
                    <td width="*" className="valign"><WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@usj86v`} columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={list} size="small"/></td>
                </tr></table>;

                docHtml = <div>{html4}</div>
                break;
            case 5: //双列式
                columns = formatData(list[0], esetting);
                const evenData = new Array;
                const oddData = new Array;
                list.map((item, i) => {
                    if (i % 2 === 0) {
                        evenData.push(item);
                    } else {
                        oddData.push(item);
                    }
                });
                if(isEmpty(evenData) && isEmpty(oddData)){
                    docHtml = <div><Row ecId={`${this && this.props && this.props.ecId || ''}_Row@tnmw88`}>
                        <div className="ant-table-placeholder"><span><i className="anticon anticon-frown"></i>{getLabel(83553, '暂无数据')}</span></div>
                    </Row>
                    </div>
                }else {
                    docHtml = <div><Row ecId={`${this && this.props && this.props.ecId || ''}_Row@gnka3o`}>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@758cpp`} span={12} order={1}>
                            {!isEmpty(evenData) && <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@fa3tn0`} columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={evenData} size="small"/>}
                        </Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@zudpxi`} span={12} order={2}>
                            {!isEmpty(oddData) && <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@0yldo4`} columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={oddData} size="small"/>}
                        </Col>
                    </Row>
                    </div>
                }
                break;
            case 6: //摘要式
                let html6 = list.map((item, i) => {
                    let docsubject = item.docsubject || {};
                    let imghtml = null;
                    if (!isEmpty(imgs)) {
                        let img = imgs[i];
                        if (typeof img == 'object' && img.length > 1) {
                            img = img.filter(item => {
                                if(item != '/images/homepage/noimgdefault_wev8.jpg'){ return item; }
                            })
                            imghtml = <div id={`news_silde_${eid}`} className="news-silde">
                                <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@2j3jjs@${i}`} autoplay >
                                    {img.map(o => {
                                        return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@wi5gv7@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link} eid={eid} src={o} style={listStyle2}/></div>
                                    })}
                                </Carousel>
                            </div>
                        } else {
                            imghtml = <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@0ljehy@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link}  eid={eid} src={img}/>
                        }
                    }
                    let style_fs = objectAssign({}, imgStyle, {float:'left'});
                    return <div className={"portal-news-com"} style={{width:'100%',paddingBottom:'20px',marginBottom:'5px',borderBottom: i !== (list.length - 1) ? '1px solid #dedede':'',overflow: 'hidden'}}>
                        <div style={style_fs}> {imghtml}</div>
                        <div style={{overflow: 'hidden', paddingLeft: '3px'}}>
                            <div style={{height:'32px',width:'99%'}}>
                                <div title={docsubject.name} onClick={openLinkUrl.bind(this, docsubject.link, esetting.linkmode)} style={{whiteSpace: 'nowrap',display:'inline-block',maxWidth:'calc(100% - 30px)',height:'100%',lineHeight:'32px',fontSize:'14px',fontWeight:'bold',color:'#666666',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 1,WebkitBoxOrient: 'vertical',cursor:'pointer'}}>{docsubject.name}</div>
                                {docsubject.img ? <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@fhyj46@${i}`} linkmode={linkmode} eid={eid} style={{verticalAlign: 'middle', marginTop: '12px', marginLeft: '5px', cursor: 'pointer'}} alt="" src={docsubject.img}/> : ''}
                            </div>
                            <div title={item.summary} style={{height: '60px', lineHeight: '30px', color: 'rgb(105, 104, 104)', textOverflow: 'ellipsis', width: '99%',
                                overflow: 'hidden', WebkitLineClamp: '2', WebkitBoxOrient: 'vertical', display: '-webkit-box',  marginBottom: '10px'}}>{item.summary}</div>
                        </div>
                    </div>
                });
                docHtml = <div className={"portal-news-content"}>{html6}</div>
                break;
            case 7: //摘要式2
                let listStyle3 = {
                    width: '100%',
                    height: '100%'
                };
                if(autoheight == '0'&& imgStyle.height && imgStyle.height.indexOf('px')!=-1){
                    listStyle3 = {
                        width: '100%',
                        height: imgStyle.height
                    };
                }
                let imghtml7 = null;
                let style_fs = objectAssign({}, imgStyle, {float: 'left', marginBottom: '15px'});
                let imghtml3= [];
                let m=0;
                let imgs2_new = imgs.filter(item => {
                    if(item != '/images/homepage/noimgdefault_wev8.jpg'){ return item; }
                })
                if (!isEmpty(imgs)) {
                    if (imgs2_new.length > 1) {
                        imgs.map((item,i) => {
                            imghtml3[m]=imgs[i];
                            m++;
                        })
                        if(imghtml3.length==0){
                            imghtml3 = ['/images/homepage/noimgdefault_wev8.jpg'];
                        }
                        let ihtml = imghtml3.map((item, i) => {
                            let img = imghtml3[i];
                            if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                            if(img == '/images/homepage/noimgdefault_wev8.jpg'){
                                return
                            }
                            if (img.indexOf("|") !== -1) img = img.split("|")[0];
                            return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@mwccsq@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link} style={listStyle3} eid={eid} src={img}/></div>
                        });
                        imghtml7 = <div id={`news_silde_${eid}`} className="news-silde">
                            <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@a67z3r`} autoplay>
                                {ihtml}
                            </Carousel>
                        </div>
                    }else{


                        let x = 0;
                        imgs.map((item, index) => {
                            if(item != '/images/homepage/noimgdefault_wev8.jpg'){
                                x = index;
                            }
                        })
                        let img = imgs2_new[0];
                        if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                        if (img.indexOf("|") !== -1) img = img.split("|")[0];
                        imghtml7 = <div style={{height: '100%'}} id={`news_silde_${eid}`} className='news-silde'>
                            <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@wiqxrt`} linkmode={linkmode} link={imgsWithDocSubject[x] && imgsWithDocSubject[x].docsubject && imgsWithDocSubject[x].docsubject.link} style={listStyle3} eid={eid} src={img}/></div>
                        </div>
                    }
                }
                let html7 = list.map((item, i) => {
                    let docsubject = item.docsubject || {};
                    return <div className={"portal-news-com"} style={{float:'left',paddingLeft:'10px',width:'100%',borderBottom:i !== (list.length - 1) ? '1px solid #dedede':''}}>
                        <div style={{height:'32px',width:'99%'}}>
                            <div title={docsubject.name} onClick={openLinkUrl.bind(this, docsubject.link, esetting.linkmode)} style={{whiteSpace: 'nowrap',display:'inline-block',maxWidth:'calc(100% - 30px)',height:'100%',lineHeight:'32px',fontSize:'14px',fontWeight:'bold',color:'#666666',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 1,WebkitBoxOrient: 'vertical',cursor:'pointer'}}>{docsubject.name}</div>

                            {docsubject.img ? <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@w7anqf@${i}`} linkmode={linkmode} eid={eid} style={{verticalAlign: 'middle', marginTop: '12px', marginLeft: '5px', cursor: 'pointer'}} alt="" src={docsubject.img}/> : ''}
                        </div>
                        <div title={item.summary} className={'portal-news-summary'} style={{display: '-webkit-box', maxHeight:'60px',width:'99%',lineHeight:'30px',color: '#696868',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 2,WebkitBoxOrient: 'vertical', marginBottom:'10px'}}>{item.summary}</div>
                    </div>

                });
                docHtml =  <div><div style={{width:'100%',marginBottom:'10px'}}>
                    <div style={style_fs}> {imghtml7}</div>
                    <div className={"portal-news-content"} style={{overflow: 'hidden'}}>{html7}</div>
                </div></div>
                break;
            case 8: //头条式
                let item = list[0];
                let docsubject = item.docsubject || {};
                let tableHtml = '';
                let newList = [...list];
                if(list.length > 1){
                    let columns = formatData(list[1], esetting);
                    tableHtml = <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@4gatn7`} columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={newList.slice(1,list.length)} size="small"/>
                }
                docHtml = <div><div style={{overflow:'hidden',width:'100%',marginBottom:'10px'}}>
                    <div className={'mews-summary'} style={{width:'100%'}}>
                        <div style={{paddingLeft:'10px',width:'100%',borderBottom:'1px solid #dedede'}}>
                            <div style={{height:'32px',width:'99%'}}>
                                <div title={docsubject.name} onClick={openLinkUrl.bind(this, docsubject.link, esetting.linkmode)} style={{padding:'3px',whiteSpace:'nowrap',fontSize: titleSize.indexOf("px")> 0 ? titleSize : titleSize +'px' || '16px', color:titleColor || '#000000',fontFamily:titleFont || '微软雅黑', fontWeight:titleWeight == '0' ? 'normal' : 'bold ', fontStyle: titlestyle || 'normal', display: 'inline-block',maxWidth: 'calc(100% - 30px)',height:'100%',lineHeight:'32px',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 1,WebkitBoxOrient: 'vertical',cursor:'pointer'}}>{docsubject.name}</div>
                                    {docsubject.img ? <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@c50g80`}  linkmode={linkmode} eid={eid} style={{verticalAlign: 'middle', marginTop: '12px', marginLeft: '5px', cursor: 'pointer'}} alt="" src={docsubject.img}/> : ''}
                            </div>
                            <div title={item.summary} className={'portal-news-summary'} style={{fontSize: abstractSize.indexOf('px') > 0 ? abstractSize : abstractSize +'px'||'16px',color:abstractColor || '#000000', fontFamily: abstractFont ||'微软雅黑', fontWeight: abstractWeight == '0' ? 'normal' : 'bold', fontStyle: abstractstyle || 'normal',width:'99%',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 2,WebkitBoxOrient: 'vertical',display: '-webkit-box', marginBottom: '10px'}}>{item.summary}</div>
                        </div></div>
                </div>
                    {tableHtml}
                </div>
                break;
            case 9: //头条式2
                let item2 = list[0];
                let docsubject2 = item2.docsubject || {};
                let tableHtml2 = '';
                let newList2 = [...list];
                if(list.length > 1){
                    let columns = formatData(list[1], esetting);
                    tableHtml2 = <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@hw8lnt`} columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={newList2.slice(1,list.length)} size="small"/>
                }

                let imghtml9=[];
                let j9=0;
                const imgs9_new = imgs.filter(item => {
                    if(item != '/images/homepage/noimgdefault_wev8.jpg'){ return item; }
                })
                if (!isEmpty(imgs)) {
                    if (imgs9_new.length > 1) {
                        imgs.map((item,i) => {
                            imghtml9[j9]=imgs[i];
                            j9++;
                        });

                        if(imghtml9.length==0){
                            imghtml9[0]='/images/homepage/noimgdefault_wev8.jpg';
                        }
                        let ihtml = imghtml9.map((item, i) => {
                            let img = imghtml9[i];
                            if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                            if(img == '/images/homepage/noimgdefault_wev8.jpg'){
                                return
                            }
                            // if (img.indexOf("|") !== -1) img = img.split("|")[0];
                            return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@1oiw3i@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link} style={listStyle2} eid={eid} src={img}/></div>
                        });
                        imghtml = <div style={{height: style.height || '100%'}} id={`news_silde_${eid}`} className="news-silde">
                            <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@r7rdop`} autoplay>
                                {ihtml}
                            </Carousel>
                        </div>
                    }else{
                        let x = 0;
                        imgs.map((item, index) => {
                            if(item != '/images/homepage/noimgdefault_wev8.jpg'){
                                x = index;
                            }
                        })
                        let img = imgs9_new[0];
                        if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                        if (img.indexOf("|") !== -1) img = img.split("|")[0];
                        imghtml = <div id={`news_silde_${eid}`} className='news-silde'>
                            <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@csakot`} linkmode={linkmode} link={imgsWithDocSubject[x] && imgsWithDocSubject[x].docsubject && imgsWithDocSubject[x].docsubject.link} style={listStyle2} eid={eid} src={img}/></div>
                        </div>
                    }
                }
                docHtml = <table style={{width: '100%',tableLayout: 'fixed'}}><tr>
                    <td style={style}>
                        {imghtml}
                    </td>
                    <td width="*" className="valign"><div><div style={{overflow:'hidden',width:'100%',marginBottom:'10px'}}>
                        <div className={'mews-summary'} style={{width:'100%'}}>
                            <div style={{paddingLeft:'10px',width:'100%',borderBottom:'1px solid #dedede'}}>
                                <div style={{height:'32px',width:'99%'}}>
                                    <div title={docsubject2.name} onClick={openLinkUrl.bind(this, docsubject2.link, esetting.linkmode)} style={{padding:'3px',whiteSpace:'nowrap',fontSize: titleSize.indexOf("px")> 0 ? titleSize : titleSize +'px' || '16px', color:titleColor || '#000000',fontFamily:titleFont || '微软雅黑', fontWeight:titleWeight == '0' ? 'normal' : 'bold ', fontStyle: titlestyle || 'normal', display: 'inline-block',maxWidth: 'calc(100% - 30px)',height:'100%',lineHeight:'32px',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 1,WebkitBoxOrient: 'vertical',cursor:'pointer'}}>{docsubject2.name}</div>
                                        {docsubject2.img ? <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@i6j6x2`} linkmode={linkmode} eid={eid} style={{verticalAlign: 'middle', marginTop: '12px', marginLeft: '5px', cursor: 'pointer'}} alt="" src={docsubject2.img}/> : ''}
                                </div>
                                <div title={item2.summary} style={{fontSize: abstractSize.indexOf('px') > 0 ? abstractSize : abstractSize +'px'||'16px',color:abstractColor || '#000000', fontFamily: abstractFont ||'微软雅黑', fontWeight: abstractWeight == '0' ? 'normal' : 'bold', fontStyle: abstractstyle || 'normal',width:'99%',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 2,WebkitBoxOrient: 'vertical',display: '-webkit-box', marginBottom: '10px', maxHeight: parseInt(abstractSize) * 2 + 6 + 'px', lineHeight: parseInt(abstractSize) + 3 + 'px'}}>{item2.summary}</div>
                            </div></div>
                    </div>
                        {tableHtml2}
                    </div></td>
                </tr></table>;
                break;
            case 10: //上图式2
                imgStyle['margin'] = '0 auto';
                let item10 = list[0];
                let tableHtml10 = '';
                let docsubject10 = item10.docsubject || {};
                let newList10 = [...list];
                if(list.length > 1){
                    let columns = formatData(list[1], esetting);
                    tableHtml10 = <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@f927b7`}  columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={newList10.slice(1,list.length)} size="small"/>
                }

                let imghtml10 = null;
                if (!isEmpty(imgs)) {
                    let img = imgs[0];
                    if (typeof img == 'object' && img.length > 1) {
                        imghtml10 = <div id={`news_silde_${eid}`} className="news-silde">
                            <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@psl7t5`} autoplay >
                                {img.map(o => {
                                    return <div><ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@j2d84s@${i}`} linkmode={linkmode} link={imgsWithDocSubject[0] && imgsWithDocSubject[0].docsubject && imgsWithDocSubject[0].docsubject.link} eid={eid} src={o} style={listStyle2}/></div>
                                })}
                            </Carousel>
                        </div>
                    } else {
                        imghtml10 = <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@cqi196`} linkmode={linkmode} link={imgsWithDocSubject[0] && imgsWithDocSubject[0].docsubject && imgsWithDocSubject[0].docsubject.link}  eid={eid} src={img}/>
                    }
                }
                let list_new = [];
                for (var i in item){
                    if(i != 'summary' && i != 'docsubject' && i != 'doccreater'){
                        list_new.push(item[i])
                    }
                }
                return <div id={`news_${eid}`} >
                    <div className={"mews-img"} style={imgStyle}>{imghtml10}</div>
                    <div className={"mews-table"} style={{width: imgStyle.width, margin: '0 auto', paddingTop: '10px'}}>
                        <td width="*" style={{display: 'block', width: '100%'}}  className="valign"><div><div style={{overflow:'hidden',width:'100%',marginBottom:'10px'}}>
                            <div style={{width:'100%'}}>
                                <div className={"mews-content"} style={{paddingLeft:'10px',width:'100%',borderBottom:'1px solid #dedede'}}>
                                    <div style={{height:'32px',width:'99%'}}>
                                        <div title={docsubject10.name} onClick={openLinkUrl.bind(this, docsubject10.link, esetting.linkmode)} style={{fontSize: titleSize.indexOf("px")> 0 ? titleSize : titleSize +'px' || '16px', color:titleColor || '#000000',
                                            fontFamily:titleFont || '微软雅黑', fontWeight:titleWeight == '0' ? 'normal' : 'bold ', fontStyle: titlestyle || 'normal', display: 'inline-block',maxWidth: 'calc(100% - 8px)',height:'100%',lineHeight:'32px',overflow:'hidden',
                                            textOverflow:'ellipsis',WebkitLineClamp: 1,WebkitBoxOrient: 'vertical',cursor:'pointer', width: 'calc(100% - 90px)',
                                            WebkitBoxRrient: 'vertical', display: '-webkit-box', float: 'left', wordBreak: 'break-all'}}>
                                            <div title={docsubject10.name} style={{display: 'flex'}}><p style={{marginRight:'3px',overflow: 'hidden',textOverflow: 'ellipsis',whiteSpace: 'nowrap'}}>{docsubject10.name}</p>
                                                {docsubject10.img ? <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@vi32pj`} linkmode={linkmode} eid={eid} style={{marginTop: '12px'}} alt="" src={docsubject10.img}/> : ''}
                                            </div>

                                        </div>
                                    </div>
                                    <div title={item10.summary} className={'portal-news-summary'}  style={{fontSize: abstractSize.indexOf('px') > 0 ? abstractSize : abstractSize +'px'||'16px',color:abstractColor || '#000000', fontFamily: abstractFont ||'微软雅黑', fontWeight: abstractWeight == '0' ? 'normal' : 'bold', fontStyle: abstractstyle || 'normal',width:'99%',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 2,WebkitBoxOrient: 'vertical',display: '-webkit-box', marginBottom: '10px'}}>{item10.summary}</div>
                                </div></div>
                        </div>
                            {tableHtml10}
                        </div></td>
                    </div>
                </div>
                docHtml = <div>{lHtml2}</div>
                break;
            case 11: //上图式3
                imgStyle['margin'] = '0 auto';
                const settings = {
                    infinite: true,
                    autoplaySpeed: parseInt(scrollSpeed),
                    className: "center",
                    dots: false,
                    rtl: rollDirection == 'right',
                    slidesToShow: list.length < this.state.count ? list.length : this.state.count,
                    slidesToScroll:1,
                    autoplay: rollDirection != 'none',
                    pauseOnHover: true,
                    draggable: false,
                };
                let lHtml11 = list.map((item, i) => {
                    const docsubject = item.docsubject;
                    let imghtml = null;
                    if (!isEmpty(imgsWithDocSubject)) {
                        let img = imgsWithDocSubject[i].imgs;
                        if(!img) img = '/images/homepage/noimgdefault_wev8.jpg';
                        imghtml = <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@luwsvo@${i}`} linkmode={linkmode} link={imgsWithDocSubject[i] && imgsWithDocSubject[i].docsubject && imgsWithDocSubject[i].docsubject.link}  eid={eid} src={img}/>
                    }
                    let list_new = [];
                    for (var i in item){
                        if(i != 'summary' && i != 'docsubject'){
                            list_new.push(item[i])
                        }
                    }
                    return <div id={`news_${eid}`} className={"portal-news-com"} style={{outline: 'none!important', width: imgStyle.width}}>
                        <div style={imgStyle}>{imghtml}</div>
                        <div style={{width: imgStyle.width, margin: '0 auto', paddingTop: '10px'}}>
                            {
                                docsubject ? <div style={{height:'32px',width:'99%'}}>
                                    <div title={docsubject.name} onClick={openLinkUrl.bind(this, docsubject.link, esetting.linkmode)} style={{padding:'3px',whiteSpace:'nowrap',fontSize: titleSize.indexOf("px")> 0 ? titleSize : titleSize +'px' || '16px', color:titleColor || '#000000',fontFamily:titleFont || '微软雅黑', fontWeight:titleWeight == '0' ? 'normal' : 'bold ', fontStyle: titlestyle || 'normal', display: 'inline-block',maxWidth: 'calc(100% - 30px)',height:'100%',lineHeight:'32px',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 1,WebkitBoxOrient: 'vertical',cursor:'pointer'}}>{docsubject.name}</div>
                                    {docsubject.img ? <ImgCom ecId={`${this && this.props && this.props.ecId || ''}_ImgCom@wtgfc6@${i}`} linkmode={linkmode} eid={eid} style={{verticalAlign: 'middle', marginTop: '12px', marginLeft: '5px', cursor: 'pointer'}} alt="" src={docsubject.img}/> : ''}
                                </div>: <div style={{ marginTop: '10px', marginRight: '10px' , marginBottom: '10px'}}></div>
                            }

                            {item.summary && <div title={item.summary} className={'portal-news-summary'} style={{fontSize: abstractSize.indexOf('px') > 0 ? abstractSize : abstractSize +'px'||'16px',color:abstractColor || '#000000', fontFamily: abstractFont ||'微软雅黑', fontWeight: abstractWeight == '0' ? 'normal' : 'bold', fontStyle: abstractstyle || 'normal',width:'99%',overflow:'hidden',textOverflow:'ellipsis',WebkitLineClamp: 2,WebkitBoxOrient: 'vertical',display: '-webkit-box', marginBottom: '10px'}}>{item.summary}</div>}
                            <div style={{display: 'inline-block', position: 'relative', width: '100%', height: '32px'}}>
                                <div style={{display: 'block', bottom: '15px', float: 'right', width: '100%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis'}}>
                                    {
                                        list_new.map((item_new, o) => {
                                            var dotstr = o === 0 ? "" : " , ";
                                            if(typeof(item_new) == "object" && item_new.userid) {
                                                var ahtml = "<a href='javascript:openhrm("+ item_new.userid +");' onclick='pointerXY(event)' title="+item_new.name+"><font style='color:#000000;display: flex;' class='font wea-f"+contentfontsize+"'>" + item_new.name+"</font></a>";
                                                if(item_new.usertype && item_new.usertype == '1') {
                                                    ahtml = "<a target='_blank' href='/spa/crm/static/index.html#/main/crm/customerView?customerId="+ item_new.userid +"' title="+item_new.name+"><font style='color:#000000;' class='font wea-f"+contentfontsize+"'>" + dotstr + item_new.name+"</font></a>";
                                                }
                                                return <div style={{display: 'block', fontSize: '12px', color: '#999999', letterSpacing: '-0.08px',paddingRight: '5px', float: 'left'}} dangerouslySetInnerHTML={{__html:ahtml}}></div>
                                            }
                                            return  <div style={{display: 'block', fontSize: '12px', color: '#999999', letterSpacing: '-0.08px',paddingRight: '5px', float: 'left'}}>{item_new}</div>
                                        })
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                });
                docHtml = <div className={"portal-news-content"} style={{overflowX: 'hidden'}}>
                    <Slider ecId={`${this && this.props && this.props.ecId || ''}_Slider@xfapki`} {...settings}>
                        {lHtml11}
                    </Slider>
                </div>
                break;
            case 1: //列表式
            default:
                columns = formatData(list[0], esetting);
                docHtml = <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@f9efjx`} style={{fontSize: '20px'}} columns={columns} showHeader={esetting.showHeader == '1'} pagination={false} dataSource={list} size="small"/>
                break;
        }
        // return <AddNewCom canEdit={this.props.canEdit} catalogIds={tabsetting.catalogIds} catalogId={tabsetting.catalogId}>{docHtml}</AddNewCom>
        return docHtml;
    }
}

class AddNewCom extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
            isShowAdd: false,
            color: '#939393',
        }
        this.handleOpen = this.handleOpen.bind(this);
    }
    handleOpen(){
        const { catalogId, catalogIds } = this.props;
        if(catalogId){
            openLinkUrl('/spa/document/index.jsp?secid='+catalogId+'&isEdit=1&moudleFrom=portal','2');
        }else{
            openLinkUrl('/spa/document/static/index.html#/main/document/add?openNewWindow=0&moudleFrom=portal&secids='+catalogIds,'2');
        }
    }
    render(){
        const { children, canEdit } = this.props;
        if(canEdit){
            return <div className=" portal-element-news-doc-add" onMouseOver={() => this.setState({isShowAdd: true})} onMouseLeave={() => this.setState({isShowAdd: false})}>
                <div title='新建文档' className={`portal-element-news-doc-add-icon ${this.state.isShowAdd ? '' : 'portal-element-news-doc-add-hidden'}`} onMouseOver={() => this.setState({color: '#434343'})} onMouseLeave={() => this.setState({color: '#939393'})} onClick={this.handleOpen} style={{color: this.state.color}}><img src='/spa/portal/images/news_add.png' alt=''/></div>
                {children}
            </div>
        }
        return <div>{children}</div>
    }
}

class ImgCom extends React.Component {
    constructor(props) {
        super(props);
        this.aClick = this.aClick.bind(this);
    }
    aClick () {
        const { link = '', linkmode='1'} = this.props;
        if(link != ''){
            openLinkUrl(link, linkmode);
            // window.open(link, linkmode);
        }else return false;
    }
    render() {
        const {src = '', style = {width: '100%', height: '100%'}, link} = this.props;
        let imgstyle = {
            display: 'inline-block', height: '100%', width: '100%'
        }
        if(!link){
            imgstyle = {
                display: 'inline-block', height: '100%'
            }
        }
        return (
            <a href="javascript:void(0)" onClick={this.aClick} style={imgstyle}>
                <img alt="" style={{...style, display: 'block'}} src={src}/>
            </a>
        );
    }
}
import { WeaErrorPage, WeaTools } from 'ecCom';
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
        return (
            <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@5zz9bz`} msg={hasErrorMsg?this.props.error:getLabel(385218,"对不起，该页面异常，请联系管理员！")} />
        );
    }
}
NewsType = WeaTools.tryCatch(React, MyErrorHandler, { error: "" })(NewsType);
export default NewsType;


